#include <iostream>
#include <cstdlib>
#include <time.h>
#define NOT_WINDOWS
#ifndef NOT_WINDOWS
#include <windows.h>
#include <conio.h>
#define HANDLE GetStdHandle(STD_OUTPUT_HANDLE)
#define red SetConsoleTextAttribute(HANDLE,FOREGROUND_RED|FOREGROUND_INTENSITY)
#define ri SetConsoleTextAttribute(HANDLE,FOREGROUND_GREEN|FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE)
#define green SetConsoleTextAttribute(HANDLE,FOREGROUND_GREEN|FOREGROUND_INTENSITY)
#else
char value;
bool kbhit(){
	value=getchar();
	return true;
}
char getch(){
	return value;
}
#endif
#include <vector>
using namespace std;
struct timexx{
	int fen,miao,hm;
	timexx(int fen,int miao,int hm): fen(fen),miao(miao),hm(hm){}
	timexx(int hm): fen(hm/CLOCKS_PER_SEC/60),miao(hm/CLOCKS_PER_SEC),hm(hm){}
	int toint(){
		int hmx;
		hmx=this->miao;
		hmx+=this->fen*60;
		hmx*=CLOCKS_PER_SEC;
		hmx+=this->hm;
		return hmx;
	}
	int operator-(timex x){
		return this->toint()-x.toint();
	}
};//ʱ��ṹ��
vector <timexx> jc;//�ƴ���Ϣ
int minti=1,maxti=1;
int now_number;//Ŀǰ�ƴ���
int main(){
	now_number=1;
	int start=clock();
	jc.push_back(timex(0));
	jc.push_back(timex(0));
	while(1){
		if(kbhit()){
			int how=getch()-'0';
			if(how==1){
				if((jc[now_number]-jc[now_number-1])<(jc[minti]-jc[minti-1])){
                    minti=now_number;
                }
                if((jc[now_number]-jc[now_number-1])>(jc[maxti]-jc[maxti-1])){
                    maxti=now_number;
                }
				now_number++;
				jc.push_back(jc[now_number-1]);
			}
			else{
				int pause=clock();
				system("clear");
				for(int i=now_number;i>0;i--){
	                if(i==minti&&now_number!=1&&i!=maxti){
#ifndef NOT_WINDOWS
    	                green;
#endif
        	        }
            	    if(i==maxti&&now_number!=1&&i!=minti){
#ifndef NOT_WINDOWS
                	    red;
#endif
	                }
					cout << "计次" << i << ":  " << jc[i].fen << ":" << jc[i].miao << ":" << jc[i].hm << "\n";
#ifndef NOT_WINDOWS
                    ri;
#endif
				}
				cout << "按1继续，按2复位";
				//while(!kbhit());
				how=getch()-'0';
				if(how!=2){
					now_number=1;
					jc.clear();
					minti=maxti=1;
					start=clock();
				}
				else{
					start+=(clock()-pause);
				}
			}
		}
		else{
			system("clear");
			long long now_hm=(clock()-start)/10;
			jc[now_number].fen=now_hm/100/60;
			jc[now_number].miao=now_hm/100%60;
			jc[now_number].hm=now_hm%100;
			for(int i=now_number;i>0;i--){
#ifndef NOT_WINDOWS
                if(i==minti&&now_number!=1&&i!=maxti){        
green;
                }
                if(i==maxti&&now_number!=1&&i!=minti){
                    red;
                }
#endif
				cout << "�ƴ�" << i << ":  " << jc[i].fen << ":" << jc[i].miao << ":" << jc[i].hm << "\n";
				#ifndef NOT_WINDOWS
                ri;
				#endif
            }
			cout << "��1�ƴΣ���2��ͣ";
		}
	}
	return 0;
}
